import matplotlib
import matplotlib.pyplot as plt

data = matplotlib.mlab.csv2rec('apache_ab_results_1000_50_happy.dat', delimiter='\t')
django = matplotlib.mlab.csv2rec('apache_ab_results_1000_50_app_db2500rows.dat', delimiter='\t')

#plot(django['starttime'], django['ttime'], '.r', label='django', color='blue')
#plot(data['starttime'], data['ttime'], '.r', label='apache', color='red')

#starttime       seconds ctime   dtime   ttime   wait


def munge_data(data, name):
    qps = {}
    for row in data:
        try:
            s = (row['seconds'] + (row['ttime'] / 1000))
            #s = row['seconds']
            qps[s] += 1

        except KeyError:
            qps[s] = 1
    print qps
    # matplotlib.pyplot.scatter(x, y, s=20, c='b', marker='o', cmap=None, norm=None, vmin=None, vmax=None, alpha=None, linewidths=None, faceted=True, verts=None, hold=None, **kwargs

    #plot(qps[''], data['ttime'], '.r', label='apache', color='red')
    #matplotlib.pyplot.scatter(qps.keys(), qps.values(), label='apache', color='blue')
    return qps

apache = munge_data(data, 'apache')
django = munge_data(django, 'django')


plt.clf()
#plt.scatter(qps.keys(), qps.values(), label=name, color=color)
plt.plot(apache.values(), label='reqs against 1000 db rows', color='blue')
plt.plot(django.values(), label='reqs against 2500 db rows', color='red')
plt.legend()
#plt.grid('.')
plt.title('apache queries/second')
plt.savefig('qpm')

